﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Basket
/// </summary>
public class Basket
{
    private List<BasketItem> items;

    public List<BasketItem> Items
    {
        get { return items; }
    }

    public Basket()
    {
        items = new List<BasketItem>();
    }

    public void Add(BasketItem item)
    {
        BasketItem b = items.FirstOrDefault(i => i.ProductCode == item.ProductCode);
        if (b != null)
        {
            items.FirstOrDefault(i => i.ProductCode == item.ProductCode).Quantity += 1;
        }
        else
        {
            items.Add(item);
        }
    }
    public void UpdateQty(BasketItem item)
    {
        if (items.Contains(item))
        {
            int index = items.IndexOf(item);
            items[index].Quantity = item.Quantity;
        }
    }

    public void Remove(BasketItem item)
    {
        if (items.Contains(item))
        {
            int index = items.IndexOf(item);
            items.RemoveAt(index);
        }
    }
}